<?php
ini_set('date.timezone','Asia/Shanghai');
//error_reporting(E_ERROR);


// 获取openid
if (!isset($_GET['code'])) {

    //获取code            
    header('Location: https://open.weixin.qq.com/connect/oauth2/authorize?appid='.'wx52de2bd8c7a64d1d'.'&redirect_uri='.urlencode('http://show.jula.cc/wxpay/example/mktpay.php').'&response_type=code&scope=snsapi_base&state=123#wechat_redirect'); 
    exit;
}

//获取openid
$url     = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".'wx52de2bd8c7a64d1d'."&secret=".'fcabaa3d11fba82fb17763fd352a0f50'."&code=".$_GET['code']."&grant_type=authorization_code";
$content = file_get_contents($url);
$ret     = json_decode($content,true);

if (isset($ret['openid'])) {

    //记录openid
    //echo "string";
    //echo $ret['openid'];

	require_once "../lib/WxPay.Api.php";
	require_once 'log.php';

	$input = new WxMktPay();


	$input->SetPartner_trade_no(date("YmdHis"));
	$input->SetCheck_name("OPTION_CHECK");
	$input->SetRe_user_name("韩建");
	$input->SetDesc("企业付款测试");
	$input->SetAmount("100");
	$input->SetOpenid($ret['openid']);
	$input->SetSpbill_create_ip('127.0.0.1');
	$result = WxPayApi::mktPay($input);
	var_dump($result);
} else {

    echo '网络请求繁忙，请稍后再试！';
    //logfile('获取用户openid失败！', 'wechat');
    exit;
}   

?>